home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MODULES / TASKKILL.ZIP / TaskKiller / TKSrc106 < prev   
Text File  |  1995-09-23  |  12KB  |  387 lines

  1. APP  : TaskKiller
  2. IN   : -
  3. OUT  : TaskKiller
  4. TYPE : Module
  5.  
  6. { Source code for Task Killer!
  7.  
  8.   Risc OS 3.11 :
  9.    Press Right-Alt-Break to kill the current task
  10.   Risc OS 3.00 :
  11.    Press Right-Alt-Scroll-lock to kill the current task
  12.   On either :
  13.    Press Right-Alt-Escape to generate error
  14.    Press Right-Alt-Keypad * to start a command prompt
  15.  
  16.   KILLING TASKS
  17.   =============
  18.   Use generate error first, this should exit most areas
  19.   Then if this doesn't work, killing should terminate the task
  20.   If you use either, then it is advised that you should reboot
  21.  
  22.                   ****** EXTREME WARNING *******
  23.       DO NOT USE THIS IF THE DESKTOP IS FUNCTIONING NORMALLY!
  24.         What will happen is that tasks will die randomly.
  25.  
  26.   COMMAND PROMPTS
  27.   ===============
  28.   This will bring up the standard * prompt from anywhere, except in the
  29.   desktop. Do not use any commands which may seriously affect the top level
  30.   application.
  31.  
  32.   DISCLAIMER
  33.   ==========
  34.   The author accepts no responsibility for this modules activities, and does
  35.   not guarentee its suitablity for any specific purpose. The module may not
  36.   be copied without this source code file.
  37.  
  38.   MAKING THIS CODE
  39.   ================
  40.   This code requires the !JFPatch pre-assembler to make the code. This is a
  41.   simple text-to-basic assembler which takes a text assembler file, makes a
  42.   basic program from it to assemble, assembles it and returns any errors.
  43.   Currently, it is under development and requires a lot of work before it
  44.   will be released in any form. As such, this file is mostly useless, but
  45.   must be distributed with the resultant module.
  46.  
  47. Contact
  48. -------
  49. Any comments, queries, donations or bug reports can be sent to :
  50.  
  51. Fidonet NetMail :  Justin Fletcher at Arcade (0181 655 4412) [2:254/27]
  52. E-Mail : Gerph@arcade.demon.co.uk
  53.  
  54. Snail Mail :
  55.     Justin Fletcher
  56.     “Galadriel”
  57.     17b Cromwell Road,
  58.     Weeting,
  59.     Brandon,
  60.     Suffolk.
  61.     IP27 0QT
  62.  
  63. History
  64. -------
  65. Version 1.00 : Simple Alt-Escape function.
  66.                Written in BASIC.
  67. Version 1.02 : Converted to Patch code.
  68.                Added Alt-Break/Shift-Lock combination
  69.                Clears Escape disabled state
  70. Version 1.03 : Added Alt-Keypad * function
  71.                Release to Arcade.
  72. Version 1.04 : Added Conditional assembly of Wimp Command window
  73.                code.
  74.                Patch code coverted to Basic by JFPatch.
  75.                FiveStar Marketting release ?
  76. Version 1.05 : 18 Mar 1995
  77.                Corrected bugs caused by incorrect pathing of Basic file
  78. Version 1.06 : 08 Apr 1995
  79.                Added code to set svc within call back code
  80.                Now uses DelinkApplication to remove vectors
  81. }
  82.  
  83. DEFINE MODULE
  84.   Name     : TaskKiller
  85.   Version  : 1.06
  86.   Date     : 08 Apr 1995
  87.   Author   : Justin Fletcher
  88.   Help     : TaskKiller
  89.   Init     : initcode%
  90.   Service  : srvcode%
  91.   Final    : finalcode%
  92.   Commands
  93.     Name   : TaskKiller
  94.     Help   : ...
  95.      The Task killer module will attempt to kill a task which has crashed.
  96.      When a task stops responding, use these keys, in order of priority :|M
  97.       1. Use Right-Alt and Escape to exit using error handler|M
  98.       2. Use Right-Alt and {k2$} to kill the task with a machette!|M|M
  99.       WARNING : Do NOT use these in a correctly functioning desktop|M|M
  100.      The Task killer module can also be used to initiate a command prompt
  101.      by Right-Alt-Keypad *.
  102.   End Commands
  103. END MODULE
  104.  
  105. PRE
  106.  DIM message_buffer% 256
  107.  *| Set Risc OS Version number
  108.  *Set RO$Version 311
  109.  *RmEnsure UtilityModule 3.11 Set RO$Version 300
  110.  *RmEnsure UtilityModule 3.00 Set RO$Version 200
  111.  riscos$=FNsystemvar("RO$Version")
  112.  REM These numbers count from top left of keyboard to bottom right
  113.  REM ie Esc = 0, f1=1, f2=2, f3=3, .. f12=12, Print=13, ScrLock=14
  114.  REM    Break =14, ~=15, 1=16, 2=17,
  115.  REM    TAB   = 38, LCtrl = 58, LShift= 75, Caps= 92
  116.  REM
  117.  k1=&60:REM Right Alt key
  118.  IF riscos$="311" THENk2=&F :k2$="Break"
  119.  IF riscos$="300" THENk2=&E :k2$="Scroll-Lock"
  120.  k3=0  :REM Escape key
  121.  k4=36 :REM Keypad *
  122.  # COND INLINE
  123.  # COND enablewimp Do you want to assemble the wimp command prompt window
  124.  REM # COND SET enablewimp FALSE
  125. END PRE
  126.  
  127. .initcode%
  128.     STMFD   (sp)!,{link}
  129.     BL      doclaim
  130.     LDMFD   (sp)!,{pc}
  131. :
  132. .srvcode%
  133.     MOV     pc,link     ; ie return immediately
  134. ;    TEQ     R1,#&27    ; reset module
  135. ;    MOVNE   pc,link
  136. :
  137. .doclaim
  138.     STMFD   (sp)!,{R0-R2,link}
  139.     MOV     link,#0
  140.     STR     link,doingnow
  141.     STR     link,key1pressed
  142.     STR     link,key2pressed
  143.     STR     link,key3pressed
  144.     STR     link,key4pressed
  145.     MOV     R0,#&10               ; vector &10 ?
  146.     ADR     R1,newvector%         ; to be processed at newvector%
  147.     BL      claimvector%
  148.     MOV     R0,#&0E
  149.     MOV     R1,#&0B
  150.     SWI     "XOS_Byte"            ; enable keypress vector
  151.     MOV     R0,#0
  152.     STRB    R0,[R12,#8]
  153.     LDMFD   (sp)!,{R0-R2,pc}
  154.  
  155. .finalcode%
  156.     STMFD   (sp)!,{R0-R2,link}
  157.     MOV     R0,#&0D
  158.     MOV     R1,#&0B
  159.     SWI     "XOS_Byte"            ; disable keypress vector
  160.     LDR     R12,[R12,#0]
  161.     MOV     R0,#&10
  162.     ADR     R1,newvector%
  163.     BL      releasevector%
  164.     LDMFD   (sp)!,{R0-R2,pc}
  165.  
  166. .claimvector%
  167.     STMFD   (sp)!,{R2,link}
  168.     BL      releasevector%
  169.     MOV     R2,#0
  170.     SWI     "XOS_Claim"
  171.     LDMFD   (sp)!,{R2,pc}^
  172.  
  173. .releasevector%
  174.     STMFD   (sp)!,{R0-R2,link}
  175. .retryrelease%
  176.     LDMFD   sp,{R0,R1}
  177.     MOV     R2,#0
  178.     SWI     "XOS_Release"
  179.     BVC     retryrelease%
  180.     CMP     pc,#0
  181.     LDMFD   (sp)!,{R0-R2,pc}
  182.  
  183. .newvector%
  184.     CMP     R0,#&0B                ; is this a keypress ?
  185.     MOVNE   pc,link                 ; if not exit
  186.     STMFD   (sp)!,{R0-r2,R4,R5,link} ; stack regs
  187.     MOV     r4,#0
  188.     CMP     R2,#k1                 ; code for key 1 (controlling key)
  189.     STREQ   R1,key1pressed
  190.     MOVEQ   r4,#1
  191.     BEQ     whichkeys%
  192.     CMP     R2,#k2                 ; code for key 2 (Kill task)
  193.     STREQ   R1,key2pressed
  194.     MOVEQ   r4,#1
  195.     CMP     R2,#k3                 ; code for key 3 (Error)
  196.     STREQ   R1,key3pressed
  197.     MOVEQ   r4,#1
  198.     CMP     R2,#k4                 ; code for key 4 (OSCLI)
  199.     STREQ   R1,key4pressed
  200.     MOVEQ   r4,#1
  201.     CMP     r4,#1
  202.     LDMNEFD (sp)!,{R0-R2,R4,R5,pc}
  203. :
  204. .whichkeys%
  205.     LDR     R2,key1pressed
  206.     TEQ     R2,#0
  207.     LDMEQFD (sp)!,{R0-R2,R4,R5,pc}
  208.     LDR     R2,key2pressed
  209.     TEQ     R2,#0
  210.     BEQ     testforkey3
  211.     ADR     r1,doexitcode%         ; r1=address to jump to
  212. .setupjump
  213.     MOV     R5,pc
  214.     BIC     R4,R5,#1
  215.     TEQP    R4,#1
  216.     MOV     R0,R0
  217.     STMFD   (sp)!,{link}
  218.     LDRB    R0,doingnow
  219.     TEQ     R0,#0
  220.     BNE     alreadydoing
  221.     MOV     r0,r1                  ; r0=address
  222.     MOV     R1,#0
  223.     SWI     "XOS_AddCallBack"
  224.     MOVVC   R0,#1
  225.     STRVCB  R0,doingnow          ; if ok then set doing
  226. .alreadydoing
  227.     LDMFD   (sp)!,{link}
  228.     TEQP    R5,#0
  229.     MOV     R0,R0
  230.     LDMFD   (sp)!,{R0-R2,R4,R5,pc}
  231. .testforkey3                     ; check that key 3 is pressed (Error)
  232.     LDR     R2,key3pressed
  233.     TEQ     R2,#0
  234.     BEQ     testforkey4
  235.     ADR     r1,doerrorcode%
  236.     B       setupjump
  237. :
  238. .testforkey4                     ; check that key 4 is pressed (OSCLI)
  239.     LDR     R2,key4pressed
  240.     TEQ     R2,#0
  241.     LDMEQFD (sp)!,{R0-R2,R4,R5,pc}
  242.     ADR     r1,doosclicode%
  243.     B       setupjump
  244. :
  245. .doexitcode%
  246.     STMFD   (sp)!,{link}
  247.     BL      delinkapplication
  248.     BL      restorebreak
  249.     MOV     R0,#0
  250.     STRB    R0,doingnow
  251. ; code goes here -
  252. ;   SWI     "OS_EnterOS"
  253.     SWI     "OS_Exit"
  254. ; - to here
  255.     LDMFD   (sp)!,{pc}
  256. :
  257. .doerrorcode%
  258.     STMFD   (sp)!,{link}
  259.     BL      delinkapplication
  260.     BL      restorebreak
  261.     MOV     R0,#0
  262.     STRB    R0,doingnow
  263. ; code goes here -
  264.     ERR     "Program terminated"
  265. ; - to here
  266.     LDMFD   (sp)!,{pc}
  267. :
  268. .delinkapplication
  269.     STMFD   (sp)!,{r0-r12,link}
  270.     FNset_as_svc(pass%)
  271. .dla_loop
  272.     ADR     r0,buffer               ; buffer for previously linked vectors ?
  273.     MOV     r1,#32                  ; length of buffer
  274.     SWI     "XOS_DelinkApplication" ; remove any vectors used by application
  275.     CMP     r1,#0                   ; was the buffer full ?
  276.     BEQ     dla_loop                ; if it was, then go around again
  277.     FNrestore_mode(pass%)
  278.     LDMFD   (sp)!,{r0-r12,pc}^
  279. .buffer
  280.     RES     32                      ; space for vector storage
  281. :
  282. :
  283. .doosclicode%
  284.     STMFD   (sp)!,{r0-r12,link}
  285.     FNset_as_svc(pass%)
  286.     BL      restorebreak
  287. ; code goes here -
  288.     ADR     r0,wimpvar              ; address of wimp variable
  289.     ADR     r1,oscliline            ; address of buffer
  290.     MOV     r2,#255                 ; buffer length
  291.     MOV     r3,#0                   ; ?
  292.     MOV     r4,#3                   ; ?
  293.     SWI     "XOS_ReadVarVal"        ; read variable
  294.     BVS     exitoscli               ; exit if error
  295.     LDR     r0,[r1,#0]              ; get first word
  296.     LDR     r2,commandstring        ; read what it should be for comm
  297.     CMP     r0,r2                   ; compare
  298.     LDRNE   r0,[r1,#0]              ; get second word
  299.     LDRNE   r2,commandstring+4      ; read what it should be for ands
  300.     CMPNE   r0,r2                   ; compare
  301.     BNE     wimprunning
  302. .oscliloop
  303.     SWI     &100+ASC("*")
  304.     ADR     r0,oscliline        ; addr of buffer
  305.     MOV     r1,#&100            ; length of buffer
  306.     MOV     r2,#&20             ; min ascii accepted
  307.     MOV     r3,#&FF             ; max ascii accepted
  308.     SWI     "XOS_ReadLine"
  309.     BVS     osclierror          ; if error then process
  310.     CMP     r1,#0               ; if no characters typed then exit
  311.     BEQ     exitoscli
  312.     SWI     "XOS_CLI"           ; do command
  313.     BVC     oscliloop           ; if no error then loop around
  314. .osclierror
  315.     ADD     r0,r0,#4            ; skip error code byte
  316.     SWI     "OS_Write0"         ; write to screen
  317.     SWI     "OS_NewLine"
  318.     B       oscliloop
  319. .exitoscli
  320.     MOV     R0,#0
  321.     STRB    R0,doingnow
  322. ; - to here
  323.     FNrestore_mode(pass%)
  324.     LDMFD   (sp)!,{r0-r12,pc}^
  325. :
  326. .wimprunning
  327. # COND OF enablewimp
  328.     ADR     r0,wimpcommand
  329.     SWI     "Wimp_StartTask"
  330. # COND END
  331. { The above two commands will create a new task with the command GOS, and
  332.   therefore open a window in the middle of the desktop. This should
  333.   not be used as on exit it tends to crash applications.
  334.   Feel free to re-enable it, but the author accepts no responsibility and
  335.   will not support bugs in this manner (unless you know a solution!) }
  336.     B       exitoscli
  337. :
  338. .restorebreak
  339.     STMFD   (sp)!,{r8-r9,link}
  340.     FNset_as_svc(pass%)
  341.     MOV     r0,#200
  342.     MOV     r1,#0
  343.     SWI     "OS_Byte"            ; Clear Break/Escape disabled
  344.     MOV     r0,#229
  345.     MOV     r1,#0
  346.     SWI     "OS_Byte"            ; Enable Escape
  347.     FNrestore_mode(pass%)
  348.     LDMFD   (sp)!,{r8-r9,pc}
  349. :
  350. ; variables
  351. .doingnow   :EQUD 0
  352. .key1pressed:EQUD 0
  353. .key2pressed:EQUD 0
  354. .key3pressed:EQUD 0
  355. .key4pressed:EQUD 0
  356. .oscliline
  357.     RES     256
  358. .wimpcommand:EQUS "GOS"+CHR$0:ALIGN
  359. .wimpvar    :EQUS "Wimp$State"+CHR$0:ALIGN
  360. .commandstring:EQUS "commands":ALIGN
  361.  
  362. # POST
  363. # RUN <CODE>
  364. # END of main code
  365. :
  366. REM FNsystemvar : Return the contents of any string system var
  367. DEFFNsystemvar(Var$):LOCAL addr
  368. SYS "XOS_ReadVarVal",Var$,message_buffer%,255,0,3TO,,len
  369. message_buffer%?len=13
  370. =$message_buffer%
  371. :
  372. DEFFNset_as_svc(pass%)
  373. [OPT pass%
  374.      MOV     r9, pc          ; save current status/mode
  375.      ORR     r8, r9, #3      ; derive SVC-mode variation of it
  376.      TEQP    r8, #0          ; enter SVC mode
  377.      MOV     r0, r0          ; nop
  378.      MOV     r8, link        ; save r14_svc
  379. ]:=pass%
  380. :
  381. DEFFNrestore_mode(pass%)
  382. [OPT pass%
  383.      MOV     link, r8        ; restore r14_svc
  384.      TEQP    r9, #0          ; re-enter original processor mode
  385.      MOV     r0, r0          ; nop
  386. ]:=pass%
  387.